import platform
import time
import traceback

from xjlibrary.mprocesspoll.process_distributed.BaseTask import BaseTask
from xjlibrary.network.MyIP import get_local_ip,GetLocalIPByPrefix


class NodeTask(BaseTask):
    def __init__(self):
        super().__init__()
        # 连接到服务器，也就是运行task_master.py的机器:
        sysstr = platform.system()
        if sysstr == "Windows":
            self.ip = GetLocalIPByPrefix("192.168.40")
        else:
            self.ip = get_local_ip("enp2s0")
        self.server_addr = self.ip
        self.port = 5000
        self.init_node(self.server_addr, self.port)


if __name__ == "__main__":
    node = NodeTask()
    node.conn()
    node.set_task_result_obj()
    while True:
        try:
            a = node.task.get(timeout=10)
            print(a)
        except:
            traceback.print_exc()
            time.sleep(5)
